package com.example.express_user.dao;

import com.example.express_user.domain.User;
import com.example.express_user.domain.UserAuth;
import com.example.express_user.domain.UserDeliveryAddress;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import javax.swing.text.StyledEditorKit;
import java.util.List;

@Mapper
public interface UserDao {
    /**
     * user register,include user,order admin
     * 用户注册 需要两个方法addUser，addUserAuth，addDeliveryAddress
     * @param userPhone
     * @param userPassword
     * @return  Boolean
     */
    @Insert("INSERT INTO user(user_phone,user_password,user_net_name,user_face) VALUES(#{userPhone},#{userPassword},#{userNetName},#{userFace})")
    Boolean addUser(String userPhone, String userPassword, String userNetName, String userFace);

    /**
     * 添加用户权限
     * @param userPhone
     * @param userAuthority
     * @return
     */
    @Insert("INSERT INTO user_auth(user_phone,user_authority) VALUES(#{userPhone},#{userAuthority})")
    Boolean addUserAuth(String userPhone, String userAuthority);

    /**
     * 初始化常用地址
     * @param userPhone
     * @return
     */
    @Insert("INSERT INTO user_delivery_address(user_phone) VALUES(#{userPhone})")
    Boolean initDeliveryAddress(String userPhone);


    /**
     * 普通用户注册快递员需要两个方法1、updateUserRealInfo,addUserAuth(添加快递员权限)
     * @param realName
     * @param idCard
     * @param familyAddress
     * @param userSex
     * @return Boolean
     */
    @Update("UPDATE user SET real_name=#{realName},id_card=#{idCard},family_address=#{familyAddress},user_sex=#{userSex} WHERE user_phone=#{userPhone}")
    Boolean updateUserRealInfo(String realName, String idCard, String familyAddress, int userSex, String userPhone);

    /**
     * 修改昵称
     * @param userPhone
     * @param userNetName
     * @return
     */
    @Update("UPDATE user SET user_net_name=#{userNetName} WHERE user_phone=#{userPhone}")
    Boolean updateUserNetName(String userPhone, String userNetName);

    /**
     * 修改头像
     * @param userPhone
     * @param userFace
     * @return
     */
    @Update("UPDATE user SET user_face=#{userFace} WHERE user_phone=#{userPhone}")
    Boolean updateUserFace(String userPhone, String userFace);

    /**
     * 更新常用收货地址
     * @param userPhone
     * @param deliveryAddress
     * @return
     */
    @Update("UPDATE user_delivery_address SET delivery_address=#{deliveryAddress} WHERE user_phone=#{userPhone}")
    Boolean updateDeliveryAddress(String userPhone, String deliveryAddress);

    @Select("select * from user where user_phone=#{userPhone}")
    User findUserByPhone(String userPhone);

    @Select("SELECT * FROM user_delivery_address WHERE user_phone=#{userPhone}")
    UserDeliveryAddress findUserDeliveryAddressByPhone(String userPhone);

    @Select("select * from user_auth where user_phone=#{userPhone}")
    List<UserAuth> findUserAuthByPhone(String userPhone);

}
